import { NativeModules } from 'react-native'
// import * as QQ from "react-native-qqsdk"
import { Jx } from "./Jx"
import { Dialog } from "./Dialog"

export class cQQandroid{
    static check(){
        return new Promise((resolve, reject)=>{
            NativeModules.uQQ.checkClientInstalled().then(r=>{
                console.log('QQ已安装');
                resolve(true);
            }).catch(err=>{
                if(err.code == 404){
                    console.warn("QQ未安装");
                }else if(err.code == 405){
                    console.warn("未找到活动块");
                    reject(0);
                }else{
                    console.warn("QQ检测错误");
                    reject(1);
                }
            })
        });
    }

    static share(image, Zone){
        return new Promise((resolve)=>{
            NativeModules.uQQ.shareImage(image, Zone)
            // QQ.shareImage(image,"","", (Zone ? QQ.shareScene.QQZone : QQ.shareScene.QQ))
            .then(r=>{
                Dialog.toast("分享成功");
                resolve(true);
            })
            .catch((err)=>{
                console.warn(Jx.stringify(err));
                if(err.code == 500){
                    Dialog.toast("分享失败");
                }else if(err.code == 503){
                    Dialog.toast("分享取消");
                }else{
                    Dialog.toast("分享失效");
                }
                resolve(false);
            });
        });
    }
}